package cn.com.zhangwoo.microstar.http.dao;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.http.util.EncodingUtils;
/****
 * 工具类
 * @author Administrator
 *
 */
public class UtilityClass {
	
	
	/**
	 * 写文本文件
	 * 在Android系统中，文件保存在 /data/data/PACKAGE_NAME/files 目录下
	 * @param context
	 * @param msg
	 */
	public static void write(String fileName, String content) 
	{ 
		if( content == null )	content = "";
		
		try 
		{
			FileOutputStream fos = new FileOutputStream(fileName);    
			
			  byte [] bytes = content.getBytes();   
			  
		        fos.write(bytes);   
		        fos.close();
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		} 
	}
	
	/**
	 * 读取文本文件
	 * @param context
	 * @param fileName
	 * @return
	 */
	public static String read(String fileName ) 
	{
		String res;
		try 
		{
			FileInputStream fis = new FileInputStream(fileName);    
			  
		        int length = fis.available();   
		  
		         byte [] buffer = new byte[length];   
		         fis.read(buffer);       
		        
		         res = EncodingUtils.getString(buffer, "UTF-8");   
		         fis.close();       
		         return res;    
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		return "";
	} 

}
